package pl.put.augrelshooter.adapters;

import java.util.Collection;

import android.content.Context;
import android.net.nsd.NsdServiceInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ServerListAdapter extends ArrayAdapter<NsdServiceInfo>{

	private final Context context;
	private NsdServiceInfo[] values;
	
	public ServerListAdapter(Context context, NsdServiceInfo[] values) {
		super(context, android.R.layout.simple_list_item_1, values);
		this.context = context;
		this.values = values;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(android.R.layout.simple_list_item_activated_1, parent, false);
		
		TextView textView = (TextView) view.findViewById(android.R.id.text1);
		textView.setText(values[position].getServiceName());
		
		return view;
	}

	@Override
	public void addAll(Collection<? extends NsdServiceInfo> collection) {
		this.values = collection.toArray(new NsdServiceInfo[collection.size()]);
	}
	
}
